﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ChangeListUtility
{
    class p4DescHanlder
    {
        public p4DescHanlder(string descOutput)
        {
        }
        /*
            string[] tagsBegin = { "Affected files ...", };
            string[] tagsEnd = { "Moved files ...", "Differences ..." };

            // get change list desc
            string prevStr = "", curStr = "";
            foreach (string line in lines)
            {
                prevStr = curStr;
                curStr = line;
                if (Array.IndexOf(tagsBegin, line) != -1)
                {
                    break;
                }
            }
            changelistDesc = prevStr;

            List<string> resultString = new List<string>();
            bool bNeedThisLine = false;
            foreach (string line in lines)
            {
                if (!bNeedThisLine)
                {
                    if (Array.IndexOf(tagsBegin, line) != -1)
                    {
                        bNeedThisLine = true;
                    }

                    continue;
                }
                if (bNeedThisLine)
                {
                    if (Array.IndexOf(tagsEnd, line) != -1)
                    {
                        bNeedThisLine = false;
                        break;
                    }
                    resultString.Add(line);
                }
            }

            /// ... //Branches/AMP/B/S/Source/Arx/Archx/Inc/AecUiCmdSlabEx.h#1 moved from //Branches/AMP/B/S/Source/Arx/Archx/Inc/AecUiCmdSlab.h#2

            // string change
            Regex r = new Regex(@"... ([/A-Za-z0-9., ]+)#(\d+) ([a-zA-Z/]+)"); 
            int[] groupNums = r.GetGroupNumbers();
            Dictionary<string, SortedDictionary<string, int>> resultDic = new Dictionary<string, SortedDictionary<string, int>>();
            foreach (string line in resultString)
            {
                Match m = r.Match(line);
                Debug.Assert(m.Success);
                
                string strOpertation = m.Groups[groupNums[3]].ToString();
                Debug.Assert(strOpertation != "branch" && strOpertation != "integrate");
                string depotName = m.Groups[groupNums[1]].ToString();
                int revision = Convert.ToInt32(m.Groups[groupNums[2]].ToString());
                resultDic[strOpertation].Add(depotName, revision);
            }

            SortedDictionary<string, int> editFiles = resultDic["edit"];
            foreach (var curfile in editFiles)
            {
                
            }
            resultDic.Remove("edit");

            SortedDictionary<string, int> movedFiles = resultDic["move/delete"];
            foreach (var curfile in movedFiles)
            {
            }
            resultDic.Remove("move/delete");

            SortedDictionary<string, int> addedFiles = resultDic["add"];
            foreach (var curfile in addedFiles)
            {
                // TODO : what?
            }
            resultDic.Remove("add");
         */

        internal void work(out string changelistDesc, out p4ChangeFileCollection changedFiles)
        {
            throw new NotImplementedException();
        }
    }
}
